import gap.maven.script.components.DefaultScriptContext;
import gap.maven.script.components.api.ArtifactFile;
import gap.maven.script.components.api.ArtifactFileFactory;
import gap.maven.script.components.api.POMArtifactFile;

import org.apache.maven.plugin.logging.Log;


final Log log = binding.getVariable("log");
final DefaultScriptContext context = binding.getVariable("context");
final ArtifactFileFactory factory = context.lookup(DefaultScriptContext.ARTIFACT_FILE_FACTORY_KEY);


POMArtifactFile file = factory.createPOMFile("org.apache.maven", "maven-artifact", "2.2.1");
file.download();
log.info("Calling from script");
log.info("Packaging Type : " + file.getPackaging());

ArtifactFile main = file.getMainArtifact();
main.download();
log.info("Artifact Id : " + main.getArtifactId());
log.info("Group Id : " + main.getGroupId());
log.info("Version : " + main.getVersion());
log.info("Type : " + main.getType());
log.info("Classifier : " + main.getClassifier());
log.info("File : " + main.getFile().getAbsolutePath());

ArtifactFile javadoc = file.getClassifier("javadoc");
javadoc.download();
log.info("Artifact Id : " + javadoc.getArtifactId());
log.info("Group Id : " + javadoc.getGroupId());
log.info("Version : " + javadoc.getVersion());
log.info("Type : " + javadoc.getType());
log.info("Classifier : " + javadoc.getClassifier());
log.info("File : " + javadoc.getFile().getAbsolutePath());

log.info("Checking getDependecyArtifactsInCompileScope");
file.getDependecyArtifactFiles().<ArtifactFile>each {
    log.info(it.groupId + ":" + it.artifactId + ":" + it.version);
    if(it.download()) {
        log.info(it.getFile().toString());
    }
};

log.info("Exiting from script");
